<?php
		     $this->load->helper('head_helper'); 
         $this->load->library('session');           
?>
<body class="fixed-top">
   <!-- BEGIN HEADER -->
   <div id="header" class="navbar navbar-inverse navbar-fixed-top">
       <!-- BEGIN TOP NAVIGATION BAR -->
       <div class="navbar-inner">
           <div class="container-fluid">
               <!--BEGIN SIDEBAR TOGGLE-->
               <div class="sidebar-toggle-box hidden-phone">
                   <div class="icon-reorder tooltips" data-placement="right" data-original-title="Toggle Navigation"></div>
               </div>
               <!--END SIDEBAR TOGGLE-->
               <!-- BEGIN LOGO -->
               <a class="brand" href="<?php echo base_url();?>sibci/">
                   <img src="<?php echo base_url();?>img/logo.png" alt="SIB" />
               </a>
               <!-- END LOGO -->
               <!-- BEGIN RESPONSIVE MENU TOGGLER -->
               <a class="btn btn-navbar collapsed" id="main_menu_trigger" data-toggle="collapse" data-target=".nav-collapse">
                   <span class="icon-bar"></span>
                   <span class="icon-bar"></span>
                   <span class="icon-bar"></span>
                   <span class="arrow"></span>
               </a>
               <!-- END RESPONSIVE MENU TOGGLER -->
                   <ul class="nav pull-right top-menu" >
                       <!-- BEGIN USER LOGIN DROPDOWN -->
                       <li class="dropdown">
                           <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                               <img src="<?php echo base_url();?>img/avatar1_small.jpg" alt="">
                               <span class="username"><?php echo $this->session->userdata('nombre_completo');?></span>
                               <b class="caret"></b>
                           </a>
                           <ul class="dropdown-menu extended logout">
                               <li><a href="#"><i class="icon-user"></i>Mi perfil</a></li>
                               <li><a href="#"><i class="icon-cog"></i>Mis configuraciones</a></li>
                               <li><a href="<?php echo base_url()."cerrar";?>"><i class="icon-key"></i>Salir</a></li>
                           </ul>
                       </li>
                       <!-- END USER LOGIN DROPDOWN -->
                   </ul>
                   <!-- END TOP NAVIGATION MENU -->
               </div>
           </div>
       </div>
       <!-- END TOP NAVIGATION BAR -->
   </div>
   <!-- END HEADER -->
   <!-- BEGIN CONTAINER -->
   <div id="container" class="row-fluid">
<?php
echo $dataMenu;
?>

      <!-- BEGIN PAGE -->
      <div id="main-content">
         <!-- BEGIN PAGE CONTAINER-->
         <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->
            <div class="row-fluid">
               <div class="span12">
                  <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                   <h3 class="page-title">
                     Facturas
                   </h3>
                   <ul class="breadcrumb">
                       <li>
                           <a href="#">Inicio</a>
                           <span class="divider">/</span>
                       </li>
                   </ul>
                   <!-- END PAGE TITLE & BREADCRUMB-->
               </div>

            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->
            <div class="row-fluid">
                <div class="span6">
                    <!-- BEGIN widget-->
                    <div class="widget purple">
                        <div class="widget-title">
                            <h4><i class="icon-reorder"></i> Formulario de ingreso de Facturas</h4>
                                    <span class="tools">
                                       <a class="icon-chevron-down" href="javascript:;" id="botonui"></a>
                                       <a class="icon-remove" href="javascript:;"></a>
                                       </span>
                        </div>
                        <div class="widget-body form">
                            <!-- BEGIN FORM-->
                            <form action="<?php echo base_url()."facturas/registro";?>" class="form-horizontal" method="post">
                            <div class="control-group">
                                <label class="control-label">Número de Factura (requerido):</label>
                                <div class="controls">
                                    <input type="text" name="numero_factura" class="span6 " required/>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">Proveedor (requerido):</label>
                                <div class="controls">
                                    <select data-placeholder="Seleccione el Proveedor" class="chzn-select-deselect span6" tabindex="0" name="id_proveedor" id="id_proveedor" required>
                                      <?php                                 
                                        echo "<option value=''></option>";     
                                      foreach ($proveedores as $proveedor) {
                                       echo "<option value='$proveedor->id_proveedor'>$proveedor->nombre_proveedor</option>";
                                      }
                                      ?>
                                    </select>
                                </div>                                
                            </div> 
                            <div class="control-group">
                                <label class="control-label">Nombre Entrega (requerido):</label>
                                <div class="controls">
                                    <input type="text" name="nombre_proveedor" class="span6 " required/>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div class="control-group">
                                <label class="control-label">Fecha de Factura (requerido):</label>
                                  <div class="controls">
                                      <input id="dp1" name="fecha_factura" type="text" value="" size="16" class="m-ctrl-medium span6" required>
                                  </div>
                            </div>  
                            <div class="control-group">
                                <label class="control-label">Fuente de Fondos (requerido):</label>
                                <div class="controls">
                                    <select data-placeholder="Seleccione la Fuente de Fondos" class="chzn-select-deselect span6" tabindex="0" name="id_fuente_fondo" id="id_fuente_fondo" required>
                                      <?php                                 
                                        echo "<option value=''></option>";     
                                      foreach ($fuenteFondo as $fuente) {
                                       echo "<option value='$fuente->id_fuente_fondo'>$fuente->nombre_fuente_fondo</option>";
                                      }
                                      ?>
                                    </select>
                                </div>                                
                            </div> 
                            <div class="control-group">
                                <label class="control-label">Número de compromiso (requerido):</label>
                                <div class="controls">
                                    <input type="text" name="numero_compromiso" class="span6" required/>
                                    <span class="help-inline"></span>
                                </div>
                            </div>                            
                            <div class="control-group">
                                <label class="control-label">Número de órden de compra:</label>
                                <div class="controls">
                                    <input type="text" name="numero_orden_compra" class="span6 " required/>
                                    <span class="help-inline"></span>
                                </div>
                            </div>  
                            <div class="control-group">
                                <label class="control-label">Requsitor (requerido):</label>
                                <div class="controls">
                                    <select data-placeholder="Seleccione el requisitor" class="chzn-select-deselect span6" tabindex="0" name="id_seccion" id="id_seccion" required>
                                      <?php                                 
                                        echo "<option value=''></option>";     
                                      foreach ($secciones as $seccion) {
                                       echo "<option value='$seccion->id_seccion'>$seccion->nombre_seccion</option>";
                                      }
                                      ?>
                                    </select>
                                </div>                                
                            </div>                                                                                   

                            <div class="form-actions">
                                <button type="submit" class="btn btn-success">Guardar</button>
                                <button type="button" class="btn">Cancelar</button>
                            </div>
                            </form>
                            <!-- END FORM-->
                        </div>
                    </div>
                    <!-- END widget-->
                </div>
                <div class="span6">
                    <!-- BEGIN widget-->
                    <div class="widget purple">
                        <div class="widget-title">
                            <h4><i class="icon-reorder"></i>
                                Formulario de búsqueda de facturas
                            </h4>
                                <span class="tools">
                                   <a class="icon-chevron-down" href="javascript:;"></a>
                                   <a class="icon-remove" href="javascript:;"></a>
                                   </span>
                        </div>
                        <div class="widget-body form switch-form">
                            <div class="widget-body form">
                            <!-- BEGIN FORM-->
                            <form action="<?php echo base_url();?>facturas/buscar" class="form-horizontal" method="POST">
                            <div class="control-group">
                                <label class="control-label">Número de Factura (requerido):</label>
                                <div class="controls">
                                    <input type="text" name="numero_factura_buscar" class="span6 " required/>
                                    <span class="help-inline"></span>
                                </div>
                            </div>
                            <div class="form-actions">
                                <button type="submit" class="btn btn-success">Buscar</button>
                            </div>
                            </form>              
                            <!-- END FORM-->                            
                            </div>
                        </div>
                    </div>
                    <!-- END widget-->
                </div>
            </div>            
                <div class="row-fluid"  id="dataTableFactura">
      
                    <div class="span12">
                        <!-- BEGIN BASIC PORTLET-->
                        <div class="widget purple">
                            <div class="widget-title">
                                <h4><i class="icon-reorder"></i>Últimas 10 Facturas</h4>
                            <span class="tools">
                                <a href="javascript:;" class="icon-chevron-down"></a>
                                <a href="javascript:;" class="icon-remove"></a>
                            </span>
                            </div>
                            <div class="widget-body" id="tableFact">
                                <table class="table table-striped table-bordered table-advance table-hover">
                                    <thead>
                                    <tr>                                
                                        <th class="hidden-phone">Número de factura</th>
                                        <th class="hidden-phone">Fecha de Ingreso</th>
                                        <th class="hidden-phone">Proveedor</th>
                                        <th class="hidden-phone">Fuente de Fondo</th>
                                        <th class="hidden-phone">Total</th>
                                        <th class="hidden-phone">Estado</th>
                                        <th class="hidden-phone">Acciones</th>                                
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr>
                                    <tbody>                            
                                        <?php
                                          foreach ($facturas as $factura) 
                                          {
                                            echo "<tr class='odd gradeX'>";
                                              echo "<td>$factura->numero_factura</td>";
                                              echo "<td>$factura->fecha_ingreso</td>";
                                              echo "<td>$factura->nombre_proveedor</td>";                                      
                                              echo "<td>$factura->nombre_fuente_fondo</td>";
                                              echo "<td> $".$factura->total."</td>";
                                              echo "<td>$factura->estado_factura</td>";
                                              //echo "<td>$factura->id_factura</td>";
                                              echo "<td>";
                                              if($factura->estado_factura == 'LIQUIDADA'){
                                                if($this->session->userdata('nombre_rol')=='BODEGA_ADMINISTRADOR'){
                                                  echo  "<a href=".base_url()."facturas/liquidar_reversa/".$factura->id_factura."><button class='btn btn-warning' title='Reversa'><i class='icon-ok'></i></button></a>";
                                                }else{
                                                  echo  "<button class='btn btn-success'><i class='icon-ok' Alt='Liquidada'></i></button>";
                                                }                                                
                                              }else{
                                                echo  "<a href=".base_url()."facturas/liquidar/".$factura->id_factura."><button class='btn btn-warning' title='Liquidar'><i class='icon-off'></i></button></a>";
                                              }
                                              echo  "<a href=".base_url()."facturas/detalle/".$factura->id_factura."><button class='btn btn-success' title='Detalle'><i class='icon-th-list'></i></button></a>";
                                              echo  "<a href=".base_url()."facturas/modif/".$factura->id_factura."><button class='btn btn-primary' title='Modificar'><i class='icon-pencil'></i></button></a>";
                                              echo  "<a href=".base_url()."facturas/acta/".$factura->id_factura." target='_blank'><button class='btn btn-primary' title='Acta'><i class='icon-file'></i></button></a>";
                                              //echo  "<button class='btn btn-danger'><i class='icon-trash'></i></button>";
                                              echo  "</td>";
                                            echo "</tr>";
                                          }
                                        ?>                                                         
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!-- END BASIC PORTLET-->
                    </div>
                      
  
                </div>            
         <!-- END PAGE CONTAINER-->
      </div>
      <!-- END PAGE -->
   </div>
   <!-- END CONTAINER -->

</div>

<?php
$this->load->helper('footer_helper');
if(isset($_POST['numero_factura_buscar'])){  
  echo"
  <script>  
    $('#botonui').click();
  </script>
  ";
}

?>
<script type="text/javascript">
function confirma(){
    if (confirm("¿Realmente desea eliminarlo?")){ 
        alert("El registro ha sido eliminado.") }
        else { 
        return false
    }
}
</script>
<script>
function rTable0(){
      $.ajax({
       type: "POST",
       url: "<?php echo base_url();?>/facturas/dataGrid",
       data: $('#numero_factura_data').val(),
       dataType: "html",
       success: function(data){
            debugger;
            $('#dataTableFactura').html(data);
            },
       error: function() { alert("oops..."); }
       });
}
</script>
<?php
if($this->session->userdata('notify0')!=''){
  echo $this->session->userdata('notify0');
  $this->session->set_userdata('notify0', ''); 
}
?>
</body>
</html>